home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / Main.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  8.8 KB  |  325 lines

  1. class Main extends State
  2. {
  3.    var mcRef;
  4.    var sSection;
  5.    var oController;
  6.    var oDynamicPack;
  7.    var bQuitting;
  8.    var bFinished;
  9.    var bCheatClothesActivated;
  10.    var bMustSendScore;
  11.    var bEasterEgg;
  12.    var oShadow;
  13.    var sState;
  14.    var game;
  15.    var sStartDynamic;
  16.    var sLastState;
  17.    var oEndScreen;
  18.    static var oRef;
  19.    static var PACKAGING_SECTION = "Packaging";
  20.    static var GAME_SECTION = "Game";
  21.    static var sSTATE_INIT = "Init";
  22.    static var sSTATE_PACKAGING = "Packaging";
  23.    static var sSTATE_GAME = "Game";
  24.    static var sSTATE_WIN = "WinScreen";
  25.    static var sSTATE_LOSE = "LoseScreen";
  26.    static var sSTATE_RESET = "Reset";
  27.    static var sSTATE_INSTRUCTIONS = "Instructions";
  28.    static var nFRAME_RATE = 35;
  29.    function Main(_mcRef)
  30.    {
  31.       super(_mcRef,false);
  32.       Stage.showMenu = false;
  33.       Main.oRef = this;
  34.       this.mcRef.onEnterFrame = Delegate.create(this,this.enterFrame);
  35.       this.sSection = Main.PACKAGING_SECTION;
  36.       this.oController = new Controller(this.mcRef);
  37.       this.oDynamicPack = null;
  38.       this.bQuitting = false;
  39.       this.bFinished = false;
  40.       this.bCheatClothesActivated = false;
  41.       this.bMustSendScore = false;
  42.       this.bEasterEgg = false;
  43.       this.oShadow = new Shadow(this.mcRef.mcShadow);
  44.       this.sState = Main.sSTATE_INIT;
  45.       this.oController.playMusicLoop(Main.PACKAGING_SECTION);
  46.    }
  47.    function doHide()
  48.    {
  49.       this.mcRef.visible = false;
  50.    }
  51.    function doShow()
  52.    {
  53.       this.mcRef.visible = true;
  54.    }
  55.    function winGame()
  56.    {
  57.       this.bFinished = true;
  58.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  59.       if(CTRLGame.getRef().Level == CTRLGame.nLEVEL1)
  60.       {
  61.          this.calculateScore();
  62.          this.oController.goToNewLevel(this.game.Screen.getInterface().mcRef.mcSongs._currentframe);
  63.       }
  64.       else
  65.       {
  66.          this.oController.goTo(Main.sSTATE_WIN,this);
  67.       }
  68.    }
  69.    function loseGame()
  70.    {
  71.       this.bFinished = true;
  72.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  73.       this.oController.goTo(Main.sSTATE_LOSE,this);
  74.    }
  75.    function startNewLevel()
  76.    {
  77.       this.bFinished = false;
  78.       var _loc2_ = CTRLGame.getRef().Level;
  79.       var _loc3_ = CTRLGame.getRef().Score;
  80.       this.game.cleanUp();
  81.       delete this.game;
  82.       this.game = null;
  83.       this.game = new CTRLGame(this.mcRef.mcState,_loc3_,_loc2_ + 1);
  84.       this.game.Screen.getInterface().doShow();
  85.    }
  86.    function updateScoreField()
  87.    {
  88.       if(this.sState == Main.sSTATE_GAME)
  89.       {
  90.          CTRLGame.getRef().Screen.getInterface().setScoreValue(CTRLGame.getRef().Score);
  91.       }
  92.       else if(this.sState == Main.sSTATE_WIN || this.sState == Main.sSTATE_LOSE)
  93.       {
  94.          this.mcRef.mcState.txtScore.text = Utils.styleNumber(CTRLGame.getRef().Score);
  95.       }
  96.    }
  97.    function doPause()
  98.    {
  99.    }
  100.    function doUnPause()
  101.    {
  102.    }
  103.    function onRestartButton()
  104.    {
  105.       this.resetForNewGame();
  106.       this.sStartDynamic = ScrollingPanel.sSTATE_TITLE;
  107.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  108.    }
  109.    function onHighScoresButton()
  110.    {
  111.       if(this.sState != Main.sSTATE_PACKAGING)
  112.       {
  113.          this.resetForNewGame();
  114.       }
  115.       this.bMustSendScore = false;
  116.       this.sStartDynamic = ScrollingPanel.sSTATE_HIGHSCORES;
  117.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  118.    }
  119.    function rollOverButton()
  120.    {
  121.       this.oController.playRollOverSound();
  122.    }
  123.    function clickPlayButton()
  124.    {
  125.       this.oController.playClickSound();
  126.       this.oController.goTo(Main.sSTATE_GAME,this);
  127.    }
  128.    function clickInstructionsButton()
  129.    {
  130.       this.oController.playClickSound();
  131.       this.oController.goTo(Main.sSTATE_INSTRUCTIONS,this);
  132.    }
  133.    function clickMenuButton()
  134.    {
  135.       this.oController.playClickSound();
  136.       this.oController.getMenu().doShow();
  137.    }
  138.    function clickQuitButton()
  139.    {
  140.       this.oController.playClickSound();
  141.       this.bQuitting = true;
  142.       this.loseGame();
  143.    }
  144.    function clickSubmitScore()
  145.    {
  146.       this.oController.playClickSound();
  147.       this.bMustSendScore = true;
  148.       this.resetForNewGame();
  149.       this.sStartDynamic = ScrollingPanel.sSTATE_HIGHSCORES;
  150.       this.oController.goTo(Main.sSTATE_PACKAGING,this);
  151.    }
  152.    function clickRestartButton()
  153.    {
  154.       this.oController.playClickSound();
  155.       this.onRestartButton();
  156.    }
  157.    function clickHighScoresButton()
  158.    {
  159.       this.oController.playClickSound();
  160.       this.onHighScoresButton();
  161.    }
  162.    function setState(_sState)
  163.    {
  164.       this.sLastState = this.sState;
  165.       super.setState(_sState);
  166.       this.initState(_sState);
  167.    }
  168.    function showHighScoreStuff(_btnSubmit)
  169.    {
  170.       _global.HS.initHiScores();
  171.       if(_global.gProxyObj.getIsLoggedIn())
  172.       {
  173.          _btnSubmit._visible = true;
  174.       }
  175.       else
  176.       {
  177.          _btnSubmit._visible = false;
  178.       }
  179.       if(_global.HS.G_ShowHighScore == false)
  180.       {
  181.          _btnSubmit._visible = false;
  182.          _btnSubmit._visible = false;
  183.       }
  184.    }
  185.    function setCheatClothes(_bActive)
  186.    {
  187.       this.bCheatClothesActivated = _bActive;
  188.    }
  189.    function setMustSendScore(_bMustSend)
  190.    {
  191.       this.bMustSendScore = _bMustSend;
  192.    }
  193.    function isCheatClothesActivated()
  194.    {
  195.       return this.bCheatClothesActivated;
  196.    }
  197.    function getSection()
  198.    {
  199.       return this.sSection;
  200.    }
  201.    function get Finished()
  202.    {
  203.       return this.bFinished;
  204.    }
  205.    function get MustSendScore()
  206.    {
  207.       return this.bMustSendScore;
  208.    }
  209.    function get EasterEgg()
  210.    {
  211.       return this.bEasterEgg;
  212.    }
  213.    function setEasterEgg(_bEasterEgg)
  214.    {
  215.       this.bEasterEgg = _bEasterEgg;
  216.    }
  217.    static function getRef()
  218.    {
  219.       return Main.oRef;
  220.    }
  221.    function Init()
  222.    {
  223.       if(this.mcRef.mcState.mcLoading._currentframe == this.mcRef.mcState.mcLoading._totalframes)
  224.       {
  225.          this.setState(Main.sSTATE_PACKAGING);
  226.          this.sStartDynamic = ScrollingPanel.sSTATE_TITLE;
  227.       }
  228.    }
  229.    function Packaging()
  230.    {
  231.    }
  232.    function Game()
  233.    {
  234.       if(Controller.getRef().isPaused() || CTRLGame.getRef().Screen.isInMiniGame())
  235.       {
  236.          if(!this.oShadow.isVisible())
  237.          {
  238.             this.oShadow.doShow();
  239.          }
  240.       }
  241.       else if(this.oShadow.isVisible())
  242.       {
  243.          this.oShadow.doHide();
  244.       }
  245.    }
  246.    function LoseScreen()
  247.    {
  248.    }
  249.    function WinScreen()
  250.    {
  251.    }
  252.    function calculateScore()
  253.    {
  254.       if(!this.bQuitting)
  255.       {
  256.          var _loc2_ = CTRLGame.getRef().Songs / Main.nFRAME_RATE;
  257.          if(_loc2_ - Math.round(_loc2_) != 0)
  258.          {
  259.             _loc2_ = Math.round(_loc2_);
  260.             _loc2_ = _loc2_ + 1;
  261.          }
  262.          else
  263.          {
  264.             _loc2_ = Math.round(_loc2_);
  265.          }
  266.          CTRLGame.getRef().addToScore(_loc2_ * LD.nSECOND_LEFT_VALUE);
  267.       }
  268.    }
  269.    function initState(_sState)
  270.    {
  271.       switch(_sState)
  272.       {
  273.          case Main.sSTATE_PACKAGING:
  274.             if(this.sLastState == Main.sSTATE_INIT)
  275.             {
  276.                this.oDynamicPack = new DynamicPack(this.mcRef.mcState,DynamicPack.sSTATE_ENTER,this.sStartDynamic);
  277.             }
  278.             else
  279.             {
  280.                this.oDynamicPack = new DynamicPack(this.mcRef.mcState,DynamicPack.sSTATE_IDLE,this.sStartDynamic);
  281.             }
  282.             break;
  283.          case Main.sSTATE_GAME:
  284.             if(this.sSection == Main.PACKAGING_SECTION)
  285.             {
  286.                this.oDynamicPack.cleanUp();
  287.                delete this.oDynamicPack;
  288.                this.oDynamicPack = null;
  289.                this.game = new CTRLGame(this.mcRef.mcState,0,1);
  290.                this.oController.playMusicLoop(Main.GAME_SECTION);
  291.                Controller.getRef().getStartPop().doInstantShow();
  292.             }
  293.             this.sSection = Main.GAME_SECTION;
  294.             break;
  295.          case Main.sSTATE_WIN:
  296.             CTRLGame.getRef().addToScore(LD.nWIN_BONUSPOINTS);
  297.          case Main.sSTATE_LOSE:
  298.             this.calculateScore();
  299.             this.oController.playMusicLoop(Main.PACKAGING_SECTION);
  300.             this.sSection = Main.PACKAGING_SECTION;
  301.             this.oEndScreen = new EndScreen(this.mcRef.mcState);
  302.             CTRLGame.getRef().Screen.getInterface().doHide();
  303.             this.oController.getMenu().doInstantHide();
  304.             this.oShadow.doInstantHide();
  305.       }
  306.    }
  307.    function enterFrame()
  308.    {
  309.       MainBroadcaster.Instance.doAction();
  310.       Broadcaster.Instance.doAction();
  311.    }
  312.    function resetForNewGame()
  313.    {
  314.       Broadcaster.Instance.flushBroadcaster();
  315.       this.oEndScreen.cleanUp();
  316.       delete this.oEndScreen;
  317.       this.oController.resetForNewGame();
  318.       this.game.cleanUp();
  319.       delete this.game;
  320.       this.game = null;
  321.       this.bQuitting = false;
  322.       this.bFinished = false;
  323.    }
  324. }
  325.